package com.group.flagtivities;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;

public class CustomItemizedOverlay extends ItemizedOverlay<CustomOverlayItem> {
	
	private ArrayList<CustomOverlayItem> mOverlays = new ArrayList<CustomOverlayItem>();
	private Context mContext;
	
	public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		mContext = context;
	}

	public void addOverlay(CustomOverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}
	
	@Override
	protected CustomOverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}
	
	@Override
	protected boolean onTap(int index) {
		int type = mOverlays.get(index).getType();
		int activity_id = mOverlays.get(index).getActivityID();
		int owner = mOverlays.get(index).getOwner();
		String description = mOverlays.get(index).getDescription();
		String room = mOverlays.get(index).getRoom();
		String title = mOverlays.get(index).getTitle();
		String start = mOverlays.get(index).getStart();
		String end = mOverlays.get(index).getEnd();
		int dislikes = mOverlays.get(index).getDislikes();
		int likes = mOverlays.get(index).getLikes();
		int attending = mOverlays.get(index).getAttending();
		Intent intent = new Intent(mContext, Detail.class);
		intent.putExtra("Details", BundleUtil.generateDetailBundle(type, activity_id, owner, description, room, title, start, end, dislikes, likes, attending));
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		mContext.startActivity(intent);
		return true;
	}
}